package cz.proks.easyhelpdesk.gwt.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;

public class WelcomeViewImpl extends Composite implements WelcomeView {
	private static WelcomeViewUiBinder uiBinder = GWT.create(WelcomeViewUiBinder.class);
	
	private Presenter presenter;
	@UiField Anchor signInAnchor;
	

	interface WelcomeViewUiBinder extends UiBinder<Widget, WelcomeViewImpl> {
	}
	
	public WelcomeViewImpl() {
		initWidget(uiBinder.createAndBindUi(this));
	}
	
	

	@Override
    protected void initWidget(Widget widget) {
        super.initWidget(widget);
        signInAnchor.addClickHandler(new ClickHandler() {
            
            @Override
            public void onClick(ClickEvent event) {
                onSignInClicked();                
            }
        });
    }

    @Override
	public void setPresenter(Presenter presenter) {
		this.presenter = presenter;
	}
    
    private void onSignInClicked() {
        String authorizationUrl = presenter.getAuthorizationUrl();
        Window.Location.assign(authorizationUrl);
    }
}
